****Analysis conducted April 4 2019**********
use "D:\Users\Anne-Marie.Jeannet\Dropbox\My Work in Progress I\ATIAS\apc paper\Age-Cohort\Methods, Data, and Analysis\MPDataset_MPDS2022_stata14.dta", clear
, clear
 
********************STEP 1. Data Preparation
*create a new variable where share of vote is a fraction and they sum to 1.00 in one country-election
generate pervote_decimal=pervote/100
*create a variable with just the election year and removing the month in the date variable*
tostring(date), replace
generate electyear=substr(date,1,4)
destring electyear, replace
label variable electyear "election year"
*aggregate the measures by country-election,weighting by party's vote share
collapse (mean) per503 per603 [aweight=pervote], by (country electyear)
*rename variables and labels
label variable per503 "Equality (weighted mean)"
rename per503 equality
label variable per603 "traditional morality (weighted mean)"
rename per603 traditionalism
*create a time series using the last possible election year as the year value for that country of equality or tradition. 
sort country electyear
bysort country: replace equality = equality[_n-1] if missing(equality)
bysort country: replace tradition = tradition[_n-1] if missing(tradition)
fillin country electyear
rename electyear year 
*summarize the country-year mean values of equality and tradition 
list country year equality tradition
export excel "manifesto data_values", firstrow(variables) replace